home *** CD-ROM | disk | FTP | other *** search
-
-
-
- GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111)))) GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111))))
-
-
-
- NNNNAAAAMMMMEEEE
- getopts, getoptcvt - parse command options
-
- SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
- ggggeeeettttooooppppttttssss optstring name [arg ...]
-
- ////uuuussssrrrr////lllliiiibbbb////ggggeeeettttooooppppttttccccvvvvtttt [----bbbb] file
-
- DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
- _g_e_t_o_p_t_s is a built-in command to _s_h(1) used to parse positional
- parameters and to check for legal options. It supports all applicable
- rules of the command syntax standard (see Rules 3-10, _i_n_t_r_o(1)). It
- should be used in place of the _g_e_t_o_p_t(1) command. See the WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
- section below.
-
- _o_p_t_s_t_r_i_n_g must contain the option letters the command using _g_e_t_o_p_t_s will
- recognize; if a letter is followed by a colon, the option is expected to
- have an argument, or group of arguments, which must be separated from it
- by white space.
-
- Each time it is invoked, _g_e_t_o_p_t_s will place the next option in the shell
- variable _n_a_m_e and the index of the next argument to be processed in the
- shell variable OOOOPPPPTTTTIIIINNNNDDDD. Whenever the shell or a shell procedure is
- invoked, OOOOPPPPTTTTIIIINNNNDDDD is initialized to 1111.
-
- When an option requires an option-argument, _g_e_t_o_p_t_s places it in the
- shell variable OOOOPPPPTTTTAAAARRRRGGGG.
-
- If an illegal option is encountered, ???? will be placed in _n_a_m_e.
-
- When the end of options is encountered, _g_e_t_o_p_t_s exits with a non-zero
- exit status. The special option ``--------'' may be used to delimit the end of
- the options.
-
- By default, _g_e_t_o_p_t_s parses the positional parameters. If extra arguments
- (_a_r_g ...) are given on the _g_e_t_o_p_t_s command line, _g_e_t_o_p_t_s will parse them
- instead.
-
- /_u_s_r/_l_i_b/_g_e_t_o_p_t_c_v_t reads the shell script in _f_i_l_e, converts it to use
- _g_e_t_o_p_t_s(1) instead of _g_e_t_o_p_t(1), and writes the results on the standard
- output.
-
- ----bbbb the results of running /_u_s_r/_l_i_b/_g_e_t_o_p_t_c_v_t will be portable to
- earlier releases of the UNIX system. /_u_s_r/_l_i_b/_g_e_t_o_p_t_c_v_t modifies
- the shell script in _f_i_l_e so that when the resulting shell script is
- executed, it determines at run time whether to invoke _g_e_t_o_p_t_s(1) or
- _g_e_t_o_p_t(1).
-
- So all new commands will adhere to the command syntax standard described
- in _i_n_t_r_o(1), they should use _g_e_t_o_p_t_s(1) or _g_e_t_o_p_t(3C) to parse positional
- parameters and check for options that are legal for that command (see the
- WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS section below).
-
-
-
- PPPPaaaaggggeeee 1111
-
-
-
-
-
-
- GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111)))) GGGGEEEETTTTOOOOPPPPTTTTSSSS((((1111))))
-
-
-
- EEEEXXXXAAAAMMMMPPPPLLLLEEEE
- The following fragment of a shell program shows how one might process the
- arguments for a command that can take the options aaaa or bbbb, as well as the
- option oooo, which requires an option-argument:
-
- while getopts abo: c
- do
- case $c in
- a | b) FLAG=$c;;
- o) OARG=$OPTARG;;
- \?) echo $USAGE
- exit 2;;
- esac
- done
- shift `expr $OPTIND - 1`
-
- This code will accept any of the following as equivalent:
-
- cmd -a -b -o "xxx z yy" file
- cmd -a -b -o "xxx z yy" -- file
- cmd -ab -o xxx,z,yy file
- cmd -ab -o "xxx z yy" file
- cmd -o xxx,z,yy -b -a file
-
- SSSSEEEEEEEE AAAALLLLSSSSOOOO
- intro(1), sh(1), getopt(3C)
-
- WWWWAAAARRRRNNNNIIIINNNNGGGGSSSS
- Although the following command syntax rule (see _i_n_t_r_o(1)) relaxations are
- permitted under the current implementation, they should not be used
- because they may not be supported in future releases of the system. As
- in the EEEEXXXXAAAAMMMMPPPPLLLLEEEE section above, aaaa and bbbb are options, and the option oooo
- requires an option-argument:
-
- cmd -aboxxx file (Rule 5 violation: options with
- option-arguments must not be grouped with other options)
- cmd -ab -oxxx file (Rule 6 violation: there must be
- white space after an option that takes an option-argument)
-
- Changing the value of the shell variable OOOOPPPPTTTTIIIINNNNDDDD or parsing different sets
- of arguments may lead to unexpected results.
-
- DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
- _g_e_t_o_p_t_s prints an error message on the standard error when it encounters
- an option letter not included in _o_p_t_s_t_r_i_n_g.
-
-
-
-
-
-
-
-
-
-
- PPPPaaaaggggeeee 2222
-
-
-
-